package com.swancloud.openstack.networking.v20210120.domain.ext.lbaasv2;

import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.google.common.base.MoreObjects;
import com.swancloud.model.network.v20210120.lbaasv2.LbV2OperatingStatus;
import com.swancloud.model.network.v20210120.lbaasv2.LbV2ProvisioningStatus;
import com.swancloud.model.network.v20210120.lbaasv2.LoadBalancerV2;
import com.swancloud.model.network.v20210120.lbaasv2.builder.LoadBalancerV2Builder;
import com.swancloud.openstack.common.ListResult;
import com.swancloud.openstack.networking.domain.ext.ListItem;

/**
 * lbaas v2 loadbalancer
 *
 * @author emjburns
 */
@JsonRootName("loadbalancer")
@JsonIgnoreProperties(ignoreUnknown = true)
public class NeutronLoadBalancerV2 implements LoadBalancerV2 {

    private String id;

    @JsonProperty("tenant_id")
    private String tenantId;

    private String name;

    private String description;

    /**
     * The ID of the subnet on which to allocate the VIP address.
     */
    @JsonProperty("vip_subnet_id")
    private String vipSubnetId;

    /**
     * The IP address of the VIP.
     */
    @JsonProperty("vip_address")
    private String vipAddress;

    @JsonProperty("admin_state_up")
    private boolean adminStateUp = true;

    @JsonProperty("provisioning_status")
    private LbV2ProvisioningStatus provisioningStatus;

    @JsonProperty("operating_status")
    private LbV2OperatingStatus operatingStatus;

    @JsonProperty("listeners")
    private List<ListItem> listeners;

    @JsonProperty("vip_port_id")
    private String vipPortId;

    private String provider;

    @JsonProperty("availability_zone")
    private String availabilityZone;
    @JsonProperty("vip_network_id")
    private String vipNetworkId;
    @JsonProperty("flavor_id")
    private String flavorId;
    @JsonProperty("vip_qos_policy_id")
    private String vipQosPolicyId;
    @JsonProperty("pools")
    private List<String> pools;
    @JsonProperty("tags")
    private List<String> tags;
    @JsonProperty("created_at")
    private Date createdAt;
    @JsonProperty("updated_at")
    private Date updateAt;


    public static LoadBalancerV2Builder builder() {
        return new LoadBalancerV2ConcreteBuilder();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getId() {
        return id;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getTenantId() {
        return tenantId;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getName() {
        return name;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getDescription() {
        return description;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getVipSubnetId() {
        return vipSubnetId;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getVipAddress() {
        return vipAddress;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean isAdminStateUp() {
        return adminStateUp;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<ListItem> getListeners() {
        return listeners;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public LbV2ProvisioningStatus getProvisioningStatus() {
        return provisioningStatus;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public LbV2OperatingStatus getOperatingStatus() {
        return operatingStatus;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getVipPortId() {
        return vipPortId;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getProvider() {
        return provider;
    }

    @Override
    public String getAvailabilityZone() {
        return availabilityZone;
    }

    @Override
    public String getVipNetworkId() {
        return vipNetworkId;
    }

    @Override
    public String getVipQosPolicyId() {
        return vipQosPolicyId;
    }

    @Override
    public String getFlavorId() {
        return flavorId;
    }

    @Override
    public List<String> getPoolIds() {
        return pools;
    }

    @Override
    public List<String> getTags() {
        return tags;
    }

    @Override
    public Date getCreatedAt() {
        return createdAt;
    }

    @Override
    public Date getUpdateAt() {
        return updateAt;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public LoadBalancerV2Builder toBuilder() {
        return new LoadBalancerV2ConcreteBuilder(this);
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("id", id)
                .add("tenantId", tenantId)
                .add("name", name)
                .add("description", description)
                .add("vipAddress", vipAddress)
                .add("vipPortId", vipPortId)
                .add("vipSubnetId", vipSubnetId)
                .add("vipNetworkId", vipNetworkId)
                .add("adminStateUp", adminStateUp)
                .add("provisioningStatus", provisioningStatus)
                .add("operatingStatus", operatingStatus)
                .add("listeners", listeners)
                .add("provider", provider)
                .add("tags", tags)
                .toString();
    }

    public static class LoadBalancersV2 extends ListResult<NeutronLoadBalancerV2> {
        private static final long serialVersionUID = 1L;

        @JsonProperty("loadbalancers")
        List<NeutronLoadBalancerV2> loadbalancers;

        @Override
        public List<NeutronLoadBalancerV2> value() {
            return loadbalancers;
        }

        @Override
        public String toString() {
            return MoreObjects.toStringHelper(this).omitNullValues()
                    .add("loadbalancers", loadbalancers).toString();
        }
    }

    public static class LoadBalancerV2ConcreteBuilder implements LoadBalancerV2Builder {
        private NeutronLoadBalancerV2 m;

        public LoadBalancerV2ConcreteBuilder() {
            this(new NeutronLoadBalancerV2());
        }

        public LoadBalancerV2ConcreteBuilder(NeutronLoadBalancerV2 m) {
            this.m = m;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public LoadBalancerV2 build() {
            return m;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public LoadBalancerV2Builder from(LoadBalancerV2 in) {
            m = (NeutronLoadBalancerV2) in;
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public LoadBalancerV2Builder tenantId(String tenantId) {
            m.tenantId = tenantId;
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public LoadBalancerV2Builder name(String name) {
            m.name = name;
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public LoadBalancerV2Builder description(String description) {
            m.description = description;
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public LoadBalancerV2Builder subnetId(String vipSubnetId) {
            m.vipSubnetId = vipSubnetId;
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public LoadBalancerV2Builder address(String vipAddress) {
            m.vipAddress = vipAddress;
            return this;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public LoadBalancerV2Builder adminStateUp(boolean adminStateUp) {
            m.adminStateUp = adminStateUp;
            return this;
        }

        @Override
        public LoadBalancerV2Builder provider(String provider) {
            m.provider = provider;
            return this;
        }

        @Override
        public LoadBalancerV2Builder availabilityZone(String availabilityZone) {
            m.availabilityZone = availabilityZone;
            return this;
        }

        @Override
        public LoadBalancerV2Builder networkId(String networkId) {
            m.vipNetworkId = networkId;
            return this;
        }

        @Override
        public LoadBalancerV2Builder portId(String portId) {
            m.vipPortId = portId;
            return this;
        }

        @Override
        public LoadBalancerV2Builder qosPolicyId(String qosPolicyId) {
            m.vipQosPolicyId = qosPolicyId;
            return this;
        }

        @Override
        public LoadBalancerV2Builder flavorId(String flavorId) {
            m.flavorId = flavorId;
            return this;
        }

        @Override
        public LoadBalancerV2Builder tags(List<String> tags) {
            m.tags = tags;
            return this;
        }
    }
}

